package com.gitee.wsl.mathematics.matrix.mat4.ext

import com.gitee.wsl.mathematics.matrix.mat2.Matrix2
import com.gitee.wsl.mathematics.matrix.mat3.Matrix3
import com.gitee.wsl.mathematics.matrix.mat4.MutableMatrix4
import com.gitee.wsl.mathematics.vector.vec2.Vector2
import com.gitee.wsl.mathematics.vector.vec3.Vector3
import com.gitee.wsl.mathematics.vector.vec4.Vector4


fun<T:Number> MutableMatrix4<T, *, *>.setRow(row: Int, vec: Vector3<T,*>, w: T) {
    this[row, 0] = vec.x
    this[row, 1] = vec.y
    this[row, 2] = vec.z
    this[row, 3] = w
}


fun<T:Number> MutableMatrix4<T, *, *>.setCol(col: Int, vec: Vector3<T,*>, w: T) {
    this[0, col] = vec.x
    this[1, col] = vec.y
    this[2, col] = vec.z
    this[3, col] = w
}

infix fun<T:Number> MutableMatrix4<T, *, *>.put(s: Number) = set(s+zero, s+zero, s+zero, s+zero)
infix fun<T:Number> MutableMatrix4<T, *, *>.put(v: Vector2<T,*>) = set(v.x, v.y, one, one)
infix fun<T:Number> MutableMatrix4<T, *, *>.put(v: Vector3<T,*>) = set(v.x, v.y, v.z, one)
infix fun<T:Number> MutableMatrix4<T, *, *>.put(v: Vector4<T,*>) = set(v.x, v.y, v.z, v.w)

fun<T:Number> MutableMatrix4<T, *, *>.set(x: T, y: T, z: T, w: T) = set(
    x, zero, zero, zero,
    zero, y, zero, zero,
    zero, zero, z, zero,
    zero, zero, zero, w)


fun<T:Number> MutableMatrix4<T, *, *>.set(mat2x2: Matrix2<T,*,*>) = set(
    mat2x2[0, 0], mat2x2[0, 1], zero, zero,
    mat2x2[1, 0], mat2x2[1, 1], zero, zero,
    zero,           zero,       zero, zero,
    zero,           zero,       zero, zero)


fun<T:Number> MutableMatrix4<T, *, *>.set(other: Matrix3<T,*,*>) = set(
    other.m00, other.m01,  other.m02,zero,
    other.m10, other.m11,  other.m12,zero,
    other.m20, other.m21,  other.m22,zero,
    zero,      zero,       zero,     one,
)


fun<T:Number> MutableMatrix4<T, *, *>.set(xAxis: Vector3<T,*>, yAxis: Vector3<T,*>, zAxis: Vector3<T,*>, pos: Vector3<T,*>) {
    m00 = xAxis.x
    m01 = xAxis.y
    m02 = xAxis.z
    m10 = yAxis.x
    m11 = yAxis.y
    m12 = yAxis.z
    m20 = zAxis.x
    m21 = zAxis.y
    m22 = zAxis.z
    m03 = pos.x
    m13 = pos.y
    m23 = pos.z
    m30 = zero
    m31 = zero
    m32 = zero
    m33 = one
}


